#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QString str = ui->editNum->text();
    int num=str.toInt();
    str = ui->editPrice->text();
    float price = str.toFloat();
    float total=num * price;
    str = str.sprintf("%.2f",total);
    ui->editTotal->setText(str);
}

void MainWindow::on_btnDec_clicked()
{
    QString str=ui->editDec->text();
    int val = str.toInt();
    str=str.setNum(val,16);
    str=str.toUpper();
    ui->editHex->setText(str);

    str=str.setNum(val,2);
    str=str.toUpper();
    ui->editBin->setText(str);
}

void MainWindow::on_btnBin_clicked()
{
    QString str=ui->editBin->text();
    bool ok;
    int val = str.toInt(&ok,2);
    str=QString::number(val,10);
    ui->editDec->setText(str);

    str=str.setNum(val,16);
    str=str.toUpper();
    ui->editHex->setText(str);
}

void MainWindow::on_btnHex_clicked()
{
    QString str=ui->editHex->text();
    bool ok;
    int val=str.toInt(&ok,16);
    str=QString::number(val,10);
    ui->editDec->setText(str);

    str=str.setNum(val,2);
    str=str.toUpper();
    ui->editBin->setText(str);
}
